<template>
    <div class="show-files">
        <!-- 左侧文件树 -->
        <el-tree class="show-files-tree" :node-key="nodeKey" default-expand-all :data="treeList" :props="defaultProps" @node-click="handleNodeClick">
            <div class="treeNode" slot-scope="{ node, data }">
                <span>{{node.label}}</span>
                <span v-show="false">{{data}}</span>
                <!-- <el-badge v-if="data != null" class="badgeItem">*必填</el-badge> -->
            </div>
        </el-tree>
        <!-- 右侧文件详细内容 -->
        <div class="show-files-list">
            <div class="title-container">
                <div class="title">附件上传</div>

            </div>
            <!-- <title></title> -->

        </div>
    </div>
</template>

<script>
export default {
    props: {
        fileList: {
            type: Array,
            default: [],
        },
        label: {
            type: String,
            default: "label",
        },
        value: {
            type: String,
            default: "value",
        },
        children: {
            type: String,
            default: "children",
        },
        nodeKey: {
            type: String,
            default: "nodeKey",
        },
    },
    data() {
        return {
            treeList: [],
            defaultProps: {
                label: this.label,
                children: this.children,
            },
        };
    },
    mounted() {
        this.treeList = JSON.parse(JSON.stringify(this.fileList));
    },
    methods: {
        handleNodeClick(obj, node, that) {
            console.log(this.treeList);
            console.log(node);
            if (node.childNodes) {
            } else {
                console.log("最后一级");
            }
        },
    },
};
</script>

<style lang="scss" scoped>
.show-files {
    display: flex;
    flex-direction: row;
    margin-top: 20px;
    font-size: 14px;

    .show-files-tree {
        max-height: 600px;
        flex: 1;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        border-radius: 5px;
        padding: 1%;
        overflow-y: scroll;
        /deep/ .el-tree-node__content {
            height: 35px;
            border-radius: 2px;
            border: 1px solid #eee;
            // 有子节点且未展开
            .el-icon-caret-right::before {
                background: url("../../assets/imgs/folder.png") no-repeat 0 0;
                content: "";
                display: block;
                width: 24px;
                height: 24px;
                font-size: 24px;
                background-size: 24px;
            }
            .el-tree-node__expand-icon {
                color: transparent;
                // 图标不旋转
                &.expanded {
                    -webkit-transform: rotate(0deg);
                    transform: rotate(0deg);
                    // 有子节点且已展开
                    &.el-icon-caret-right::before {
                        background: url("../../assets/imgs/folderOpen.png")
                            no-repeat 0 0;
                        content: "";
                        display: block;
                        width: 24px;
                        height: 24px;
                        font-size: 24px;
                        background-size: 24px;
                    }
                }
                // 没有子节点
                &.is-leaf::before {
                    background: url("../../assets/imgs/file.png") no-repeat 0 0;
                    content: "";
                    display: block;
                    width: 24px;
                    height: 24px;
                    font-size: 24px;
                    background-size: 24px;
                }
            }
        }
    }
    .show-files-list {
        flex: 2;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
        border-radius: 5px;
        font-size: 15px;
        padding: 0 15px;
        line-height: 44px;
    }
}
</style>